package com.woniuxy.creditsystem.applymag.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.applymag.service.IApplyService;
import com.woniuxy.creditsystem.common.bean.ApplyInfo;
import com.woniuxy.creditsystem.common.bean.DtoApply;
import com.woniuxy.creditsystem.common.mapper.ApplyMapper;
import com.woniuxy.creditsystem.common.mapper.CustomerMapper;
import com.woniuxy.creditsystem.common.util.PageRest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(readOnly = true)
public class ApplyServiceImpl implements IApplyService {

    @Resource
    private ApplyMapper applyMapper;

    @Resource
    private CustomerMapper customerMapper;

    @Override
    public List<DtoApply> findAll() {
        /**
         * create by: zhengbin
         * description:
         * create time: 2020/12/11 0011
         * @参数 []
         * @return java.util.List<com.woniuxy.creditsystem.common.bean.ApplyInfo>
         * @修改人和其它信息
         */
        System.out.println("开始。。。");
        return applyMapper.findAll();
    }

    @Override
    public List<DtoApply> findByStatus(String status) {
        return applyMapper.findByStatus(status);
    }

    @Override
    public PageInfo findByParam(PageRest pageRest, DtoApply dtoApply) {
        /**
         * create by: zhengbin
         * description:
         * create time: 2020/12/11 0011
         * @参数 [pageRest, applyInfo]
         * @return com.github.pagehelper.PageInfo
         * @修改人和其它信息
         */
        System.out.println("分页查询");

        return PageHelper.startPage(pageRest.getPageNum(),pageRest.getLimit()).doSelectPageInfo(()->applyMapper.findByParam(pageRest,dtoApply));
    }


    @Override
    public ApplyInfo findById(long id) {
        /**
         * create by: zhengbin
         * description:
         * create time: 2020/12/11 0011
         * @参数 [id]
         * @return com.woniuxy.creditsystem.common.bean.ApplyInfo
         * @修改人和其它信息
         */
        System.out.println("详情");

        return applyMapper.findByID(id);
    }

    @Override
    public List<DtoApply> findNotTrail() {
        return applyMapper.findNotTrail();
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveApply(ApplyInfo applyInfo) {
        /**
         * create by: zhengbin
         * description:
         * create time: 2020/12/11
         * @参数 [applyInfo]
         * @return int
         * @修改人和其它信息
         */

        int a=customerMapper.saveCustomer(applyInfo.getCustomerInfo());
        System.out.println("新增客户："+a);
        return applyMapper.saveApply(applyInfo);
    }

    @Override
    public int updateApply(ApplyInfo applyInfo) {
        /**
         * create by: zhengbin
         * description:
         * create time: 2020/12/11 0011
         * @参数 [applyInfo]
         * @return int
         * @修改人和其它信息
         */
        return applyMapper.updateApply(applyInfo);
    }
}